<template>
    <div class="login">
        <div class="login_box">
            <div class="login_logo">
                <img src="@/assets/logo.png" alt="">
            </div>
            <el-form :model="loginInfo" status-icon :rules="rules" ref="ruleForm" label-width="20px"
                class="demo-ruleForm">
                <el-form-item prop="username">
                    <el-input v-model="loginInfo.username" prefix-icon="el-icon-user-solid"></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input v-model="loginInfo.password" prefix-icon="el-icon-s-goods"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="loginBtn">登录</el-button>
                    <el-button type="info">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import { mapActions } from 'vuex';
export default {
    data() {
        return {
            loginInfo: {
                username: "admin",//用户名
                password: "123456",//密码
            },
            rules: {
                username: [
                    { required: "true", message: "用户名不能为空", trigger: "blur" }
                ],
                password: [
                    { required: "true", message: "密码不能为空", trigger: "blur" }
                ]
            }
        }
    },
    methods: {
        ...mapActions('login', ['loginActions']),
        // 点击登录按钮
        loginBtn() {
            this.$refs.ruleForm.validate(async isOk => {
                if (!isOk) return this.$message.info('校验失败')
               try {
                await this.loginActions(this.loginInfo)
                this.$router.push('/home')
                this.$message.success('登录成功')
               } catch (error) {
                this.$message.error('登录失败')
               }
            })
        }
    },
}
</script>

<style lang="scss" scoped>
.el-form {
    margin-right: 20px;
}

::v-deep .el-form-item__content {
    display: flex;
    justify-content: flex-end;
}

.login {
    width: 100vw;
    height: 100vh;
    background: #2b4b6b;

    .login_box {
        width: 450px;
        height: 300px;
        background: white;
        position: fixed;
        bottom: 0;
        left: 0;
        top: 0;
        right: 0;
        margin: auto;
        position: absolute;

        .login_logo {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            border: 1px solid #ccc;
            position: relative;
            background: white;

            img {
                width: 90px;
                height: 90px;
                border-radius: 50%;
                background: #eeeeee;
            }

            top: -50px;
            left: 175px;
        }
    }
}
</style>